<?php

/**
 * 模型对应数据库表 "information".
 *
 * 以下是可用表information的栏位:
 * @property string $id
 * @property integer $info_sort
 * @property integer $select_game
 * @property string $info_title
 * @property string $info_content
 * @property string $info_about
 * @property integer $info_number
 * @property string $info_top
 * @property string $info_keyword
 * @property string $info_creator
 * @property string $info_datetime
 * @property string $info_image
 * @property integer $info_state
 * @property integer $info_index
 * @property string $info_form
 * @property string $option_date
 * @property string $info_website
 */
class Information extends CActiveRecord {

    public $totel;

    /**
     * 返回指定的基于“ar”的静态模型类.
     * @return Information the static model class
     * @author nirsh
     * @example
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * 返回数据库表的名.
     * @author nirsh
     * @version 5.0
     * @example
     */
    public function tableName() {
        return 'web_information';
    }

    /**
     * 返回验证规则 
     * @author nirsh 
     * @version 5.0 
     * @example 
     */
    public function rules() {
        return array(
            array('info_sort, info_title, info_content, info_website', 'required'),
            array('info_sort, info_number, info_state, info_index,select_game ', 'numerical', 'integerOnly' => true),
            array('info_title, info_keyword, info_image, info_form', 'length', 'max' => 255),
            array('info_top', 'length', 'max' => 1),
            array('info_creator', 'length', 'max' => 50),
            array('info_website', 'length', 'max' => 100),
            array('info_about, info_datetime', 'safe'),
            // The following rule is used by search(). 
            // Please remove those attributes that should not be searched. 
            array('id, info_sort, select_game, info_title, info_content, info_about, info_number, info_top, info_keyword, info_creator, info_datetime, info_image, info_state, info_index, info_form, option_date, info_website', 'safe', 'on' => 'search'),
        );
    }

    /**
     * 返回关联规则数组。
     * @author nirsh
     * @version 5.0
     * @example
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * 通过ID获取名称
     * @author nirsh
     * @version 5.0
     * @example
     */
    public function getNameById($id, $nameField) {
        $res = $this->findByPk($id);
        return $res[$nameField] ? $res[$nameField] : '';
    }

    /**
     * 返回属性标签(名称= >标签)数组
     * @author nirsh
     * @version 5.0
     * @example
     */
    public function attributeLabels() {
        return array(
            'id' => '编号',
            'info_sort' => '资讯分类',
            'info_title' => '资讯标题',
            'info_about' => '资讯简介',
            'info_content' => '资讯内容',
            'info_number' => '点击次数',
            'info_top' => '是否置顶',
            'info_keyword' => '关键字',
            'info_creator' => '作者',
            'info_datetime' => '创建时间',
            'info_image' => '资讯缩略图',
            'info_state' => '资讯状态',
            'info_index' => '首页显示',
            'info_form' => '资讯来源',
            'option_date' => '操作日期',
            'info_website' => '站点',
            'select_game' => '选择游戏'
        );
    }

    /**
      +-----------------------------------------------------
     * 说明 获取新闻副标题
     * @param 
     * @return 
     * @author vseach@163.com
      +-----------------------------------------------------
     * @example
     */
    public function getChildTitle() {
        return "";
    }

    /*
     * 是否首页显示
     */

    public $index_array = array(
        '0' => '不显示',
        '1' => '显示',
    );


    /*
     * 发布状态
     */
    public $state_array = array(
        '0' => '审核',
        '1' => '发布',
    );

    /**
     * 是否置顶
     * @var type 
     */
    public $top_array = array(
        '0' => '一般',
        '1' => '置顶'
    );

    /**
     * 设置查询相关条件
     * @author nirsh
     * @version 5.0
     * @example
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;
        $criteria->compare('id', $this->id, true);
        $criteria->compare('info_sort', $this->info_sort);
        $criteria->compare('select_game', $this->select_game);
        $criteria->compare('info_title', $this->info_title, true);
        $criteria->compare('info_content', $this->info_content, true);
        $criteria->compare('info_about', $this->info_about, true);
        $criteria->compare('info_number', $this->info_number);
        $criteria->compare('info_top', $this->info_top, true);
        $criteria->compare('info_keyword', $this->info_keyword, true);
        $criteria->compare('info_creator', $this->info_creator, true);
        $criteria->compare('info_datetime', $this->info_datetime, true);
        $criteria->compare('info_image', $this->info_image, true);
        $criteria->compare('info_state', $this->info_state);
        $criteria->compare('info_index', $this->info_index);
        $criteria->compare('info_form', $this->info_form, true);
        $criteria->compare('option_date', $this->option_date, true);
        if (!empty($this->info_website)) {
            $criteria->compare('info_website', $this->info_website);
        } else {
            $criteria->compare('info_website', Yii::app()->params->site_id);
        }
        return new CActiveDataProvider(get_class($this), array(
                    'criteria' => $criteria,
                    'pagination' => array(
                        'pageSize' => 20,
                    ),
                    'sort' => array(
                        'defaultOrder' => 'id DESC'
                    )
                ));
    }

    /**
      +-----------------------------------------------------
     * 说明  获取资讯游戏分类
     * @param 
     * @return 
     * @author vseach@163.com
      +-----------------------------------------------------
     * @example
     */
    public function getInfoGameCategory() {
        $cdbc = new CDbCriteria;
        $cdbc->select = "select_game,Count(select_game) as totel";
        $cdbc->group = "select_game";
        $cdbc->compare('info_website', Yii::app()->params->site_id);
        return $this->findAll($cdbc);
    }

    /**
      +-----------------------------------------------------
     * 说明 获取游戏分类
     * @param 
     * @return 
     * @author vseach@163.com
      +-----------------------------------------------------
     * @example
     */
    public function getNewsCategory() {
        $cdbc = new CDbCriteria;
        $cdbc->select = "info_sort,Count(info_sort) as totel";
        $cdbc->group = "info_sort";
        $cdbc->compare('info_website', Yii::app()->params->site_id);
        return $this->findAll($cdbc);
    }

    /**
      +-----------------------------------------------------
     * 说明 获取所以新闻
     * @param 
     * @return 
     * @author vseach@163.com
      +-----------------------------------------------------
     * @example
     */
    public function findByDomain() {
        $cdbc = new CDbCriteria;
        $cdbc->compare('info_website', Yii::app()->params->site_id);
        return $this->findAll($cdbc);
    }

}